#!/usr/bin/env python
# encoding: utf-8
"""
Shovelhead
File: Environment.py
Author: Myriam Boucher

Reverb used on the object (objEngine) for simulating the
reverberation of a physical space.

Also but to expensive (commented out): Convolution reverb used on the object (objEngine) for digitally simulating the
reverberation of a physical space. It uses a pre-recorded audio sample of the impulse
response of the space being modeled(given as the argument impulse). 
"""

#TO DO: implement the reverb-convolution.

from pyo import *

class Environment:
    def __init__(self, environment, objEngine):

        self.motor = objEngine
        self.environment = environment
        self.traitement = WGVerb(self.motor.getMixEngine(), feedback=0.60, cutoff=5000, bal=0.50, mul=.7, add=0)
        
        #self.traitementConvolution = Convolve(self.mixEngine, SndTable(self.environment), size=512, mul=.2)
        
    def outReverb(self):
        # apply the effect on the sound of the engine.
        if self.environment == 'garage':
            self.traitement.setFeedback(.6)
        elif self.environment == 'church':
            self.traitement.setFeedback(.9)
            self.traitement.setCutoff(2000)

        self.traitement.out()
        #self.traitementConvolution.out()
        return self
    
    def stopReverb(self):
        # stop the WGVerb object.
        self.traitement.stop()
        #self.traitementConvolution.stop()
        return self